package com.metaverse.backend.domain;

import com.metaverse.backend.enums.LoginType;
import com.metaverse.backend.annotations.ExcelTitle;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.time.LocalDateTime;


@Data
@Entity
@Table(indexes = {
        @Index(columnList = "userId"),
})
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ExcelTitle("资产")
@ApiModel("登录日志")
public class LoginLog extends BaseEntity {
    /**
     * 登录手机号
     */
    private String phone;
    /**
     * 登录Id
     */
    private Long userId;
    /**
     *登录时间
     */
    private LocalDateTime loginTime;
    /**
     *登录状态
     */
    private boolean loginSuccess;
    /**
     *登录IP
     */
    private String ipAddress;
    /**
     *客户端类型
     */
    private String clientType;
    /**
     * 操作系统类型
     */
    private String os;
    /**
     * 浏览器类型
     */
    private String browser;
    /**
     * 登录方式
     */
    @Enumerated(EnumType.STRING)
    private LoginType loginType;

    public LoginLog(Boolean loginSuccess,LoginType loginType,String phone,Long loginUserId) {
        this.loginSuccess = loginSuccess;
        this.loginType = loginType;
        this.phone = phone;
        this.loginTime = LocalDateTime.now();
        this.userId = loginUserId;
    }
}
